package com.xkdx.caipiao.presistence.login;

import android.content.Context;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xkdx.caipiao.MyLotterActivity;
import com.xkdx.caipiao.fragment.MyLotterFragment;
import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.util.SharePrefenceUtil;

public class LoginModule extends AbsModule {
	public LoginInfo loginInfo;
	public String code = "";
	private Context context;

	public LoginModule(Context cx) {
		this.context = cx;
	}

	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;
			for (int i = 0; i < backJson.size(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				code = jsonObj.getString("Code");
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("Login")) {
					parseLogin(jsonObj.getJSONObject("DetailInfo"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private void parseLogin(JSONObject person) throws Exception {
		try {
			loginInfo = new LoginInfo();
			loginInfo.setCreate_time(person.getString(LoginInfo.CREATE_TIME));
			loginInfo.setId(person.getString(LoginInfo.ID));
			loginInfo.setDevicetype((person.getString(LoginInfo.DEVICETYPE)));
			loginInfo.setLast_login_ip(person
					.getString(LoginInfo.LAST_LOGIN_IP));
			loginInfo.setLast_login_time(person
					.getString(LoginInfo.LAST_LOGIN_TIME));
			loginInfo.setLevel(person.getString(LoginInfo.LEVEL));
			loginInfo.setLogintoken(person.getString(LoginInfo.LOGINTOKEN));
			loginInfo.setMoney(person.getString(LoginInfo.MONEY));
			loginInfo.setRedbox(person.getString(LoginInfo.REDBOX));
			loginInfo.setScore(person.getString(LoginInfo.SCORE));
			loginInfo.setSign_words(person.getString(LoginInfo.SIGN_WORDS));
			loginInfo.setStatus(person.getString(LoginInfo.STATUS));
			loginInfo.setUser_login_name(person
					.getString(LoginInfo.USER_LOGIN_NAME));
			loginInfo.setUser_nickname(person
					.getString(LoginInfo.USER_NICKNAME));
			loginInfo.setUser_pass(person.getString(LoginInfo.USER_PASS));
			loginInfo.setUser_pic_assetid(person
					.getString(LoginInfo.USER_PIC_ASSETID));
			loginInfo.setVerify(person.getString(LoginInfo.VERIFY));
			
			MyLotterActivity.loginInfo=loginInfo;
			SharePrefenceUtil su = new SharePrefenceUtil(context,
					SharePrefenceUtil.USERINFO);
			su.saveObject(SharePrefenceUtil.USERINFO, loginInfo);
		} catch (Exception e) {
			
			throw e;
		}
	}
}
